import { createRouter, createWebHistory } from 'vue-router'
import PhotoList from '../views/PhotoList.vue'
import PhotoView from '../views/PhotoView.vue'
// import VideoView from '../views/VideoView.vue'
import { usePhotoStore } from '../stores/photo'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'PhotoList',
      component: PhotoList
    },
    {
      path: '/photo/:url',
      name: 'PhotoView',
      component: PhotoView
    // },
    // {
    //   path: '/video/:url',
    //   name: 'VideoView',
    //   component: VideoView
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.name === 'PhotoList' && from.name === 'PhotoList') {
    const photoStore = usePhotoStore()
    // 重置状态和获取新数据的逻辑移到这里
    photoStore.reset() // 重置 store 状态
  }
  next()
})

export default router